(function(win){
	var Z = win.Z,
	Bundle = Z.Bundle,
	BundleList = Z.BundleList,
	bundle = new Bundle({'tmpl' : 'goodsImage'}),
	loader;

	bundle.addEvent('a.gen', 'click', function(){
		Z.confirm('确定要重新生成吗？', function(){
			Z.ajax({'url' : Z.route('goodsImage','gen')});
		});
	});


	bundle.addEvent('a.sort', 'click', function(){
		var field = $(this).data('field');
		loader.load({'orderField' : field});
	});
	
	bundle.onload = function(){
		Z.loadScript('lib/jquery.adaptive', function(){
			loader = new Z.Loader({
				'url' : Z.route('goodsImage','records'), 
				'listTmpl' : bundle.find('script.list-tmpl').html(),
				'list' : bundle.find('ul.records'),
				'pagination' : bundle.find('div.pagination')
			});

			loader.onload = function(){
				$('ul.records li img').each(function(i,item){
					var width = 210;
					var height = 210;
					$(this).adaptive(width,height);
				});
			};

			loader.load({'pageSize' : 15});
		});
	};
	
	BundleList.append(bundle);
})(window);